package my.yuan.fkzapp.response;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;
import java.util.List;

/**
 * @author qy
 * @description z
 * @date 2021-10-01
 */
@ApiModel(value = "全局分页返回结果")
public class CommonPage<T> implements Serializable {

    private static final long serialVersionUID = 8347835465614564827L;
    @ApiModelProperty(value = "当前页码")
    private Integer pageNum;
    @ApiModelProperty(value = "每页大小")
    private Integer pageSize;
    @ApiModelProperty(value = "总页数")
    private Integer totalPage;
    @ApiModelProperty(value = "总条数")
    private Long totalCount;
    @ApiModelProperty(value = "分页数据")
    private List<T> list;

    public CommonPage() {
    }

    public CommonPage(Integer pageNum, Integer pageSize, Integer totalPage, Long totalCount, List<T> list) {
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.totalPage = totalPage;
        this.totalCount = totalCount;
        this.list = list;
    }

    public static <T> CommonPage<T> toCommonPage(IPage<T> page) {
        return new CommonPage<>((int) page.getCurrent(), (int) page.getSize(), (int) page.getPages(), page.getTotal(), page.getRecords());
    }

}
